<?php
/**
 * Created by PhpStorm.
 * User: Silent
 * Date: 2018/9/5
 * Time: 11:35
 */
$file_url = "test.txt";
function ready(){
    global  $file_url;
    if(file_exists($file_url)){
        $fp = fopen($file_url,"r");
//        $fp.lock
        $str = "";
        $buffer = 1024;//每次读取 1024 字节
        while(!feof($fp)){//循环读取，直至读取完整个文件
            $str .= fread($fp,$buffer);
        }
        $arr = explode("\n",$str);
//    $str = str_replace("\r\n","<br />",$str);
        var_dump($arr);
        fclose($fp);//文件关闭
    }
}
function write(){
    global  $file_url;
    $myfile = fopen($file_url, "w") or die("Unable to open file!");
    $txt = "Bill Gates\n";
    fwrite($myfile, $txt);
    $txt = "Steve Jobs\n";
    fwrite($myfile, $txt);
    file_put_contents($myfile,$txt,LOCK_EX);
//记得关闭流
    fclose($myfile);
}
write();
//ready();

?>